package com.jt.consumer.service.factory;

import com.jt.consumer.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 *远程服务回调工程，当远端服务不可用时，可以
 *通过此工厂创建一个service对象，返回一些友好信息
 */
@Component
public class ProviderFallbackFactory
        implements FallbackFactory<RemoteProviderService> {
    @Override
    public RemoteProviderService create(Throwable throwable) {
//       return new RemoteProviderService() {//匿名内部类
//           @Override
//           public String echoMessage(String msg) {
//               return "服务忙，稍等片刻再访问";
//           }
//       };
        //JDK8中lambda表达式
        return (msg)->{
            return "服务忙，稍等片刻再访问";
        };
    }
}
